package net.qiqbframework.modelling.command;

import net.qiqbframework.messaging.task.CurrentMessageTask;

import java.util.HashMap;

public class CommandAggregateContext {

    private static final String FETCH_SOURCE = "_fetchSource";

    public static void setAggregateFetchSource(String aggregateName, String aggregateId, Integer fetchSource) {
        final HashMap<Object, Object> aggregateFetchSource = CurrentMessageTask.get().getOrDefaultResource(FETCH_SOURCE + ":" + aggregateName, new HashMap<>());
        aggregateFetchSource.put(aggregateId, fetchSource);
    }

    public static Integer getAggregateFetchSource(String aggregateName, String aggregateId) {
        final HashMap<Object, Object> aggregateFetchSource = CurrentMessageTask.get().getResource(FETCH_SOURCE + ":" + aggregateName);
        return (Integer) aggregateFetchSource.get(aggregateId);
    }
}
